- /* sxfbcoss.cpp by K.Tsuru */
- // function ID 5202 BRADIX
- #ifndef SN_H
- #include "sn.h"
- #endif
- /***************
- SDecimal class
- cos x by series
- ****************/
- SDecimal BcosSeries(const SDouble& x){
- SDouble Xsq(x*x);
- SDecimal sum(1.0), xsq, delta, q;
- xsq = q.ConvToBin(Xsq);
- XsDiv(xsq, 2, delta);
- ulong mt = delta.SlOpMaxValue(), n = 3, den;
-
- XXSub(sum, delta, sum);
-
- do{
- den = n*(n+1);
- if(den > mt) break;
- q = delta*xsq;
- XsDiv(q, den, delta);
-
- if(n & 2) XXAdd(sum, delta, sum);
- else XXSub(sum, delta, sum);
- n += 2;
- } while(delta.Sign());
-
- while(delta.Sign()){
- if(n > mt){
- sum.SetError(sum.NOT_CONVERGE,"BcosSeries", -5202);
- break;
- }
- q = delta*xsq;
- XsDiv(q ,n, delta);
- XsDiv(delta, n+1, delta);
-
- if(n & 2) XXAdd(sum, delta, sum);
- else XXSub(sum, delta, sum);
- n += 2;
- }
- sum.upToTerm = (long)n/2;
- return sum;
- }
sxfbcoss.cpp : last modifiled at 2015/12/15 13:58:41(915 bytes)
created at 2015/12/22 16:09:56
The creation time of this html file is 2017/10/27 15:45:59 (Fri Oct 27 15:45:59 2017).